/*  1:   */ package org.jetbrains.jps.model.serialization;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.util.JDOMUtil;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */ 
/* 10:   */ public class JDomSerializationUtil
/* 11:   */ {
/* 12:   */   @NonNls
/* 13:   */   protected static final String COMPONENT_ELEMENT = "component";
/* 14:   */   @NonNls
/* 15:   */   protected static final String OPTION_ELEMENT = "option";
/* 16:   */   @NonNls
/* 17:   */   protected static final String NAME_ATTRIBUTE = "name";
/* 18:   */   @NonNls
/* 19:   */   protected static final String VALUE_ATTRIBUTE = "value";
/* 20:   */   
/* 21:   */   @Nullable
/* 22:   */   public static Element findComponent(@Nullable Element paramElement, @NonNls String paramString)
/* 23:   */   {
/* 24:35 */     for (Element localElement : JDOMUtil.getChildren(paramElement, "component")) {
/* 25:36 */       if (localElement.getAttributeValue("name").equals(paramString)) {
/* 26:37 */         return localElement;
/* 27:   */       }
/* 28:   */     }
/* 29:40 */     return null;
/* 30:   */   }
/* 31:   */   
/* 32:   */   public static Element createComponentElement(String paramString)
/* 33:   */   {
/* 34:44 */     Element localElement = new Element("component");
/* 35:45 */     localElement.setAttribute("name", paramString);
/* 36:46 */     return localElement;
/* 37:   */   }
/* 38:   */   
/* 39:   */   @NotNull
/* 40:   */   public static Element findOrCreateComponentElement(@NotNull Element paramElement, @NotNull String paramString)
/* 41:   */   {
/* 42:51 */     if (paramElement == null) {
/* 43:51 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/serialization/JDomSerializationUtil", "findOrCreateComponentElement" }));
/* 44:   */     }
/* 45:51 */     if (paramString == null) {
/* 46:51 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "1", "org/jetbrains/jps/model/serialization/JDomSerializationUtil", "findOrCreateComponentElement" }));
/* 47:   */     }
/* 48:51 */     Element localElement = findComponent(paramElement, paramString);
/* 49:52 */     if (localElement == null)
/* 50:   */     {
/* 51:53 */       localElement = createComponentElement(paramString);
/* 52:54 */       addComponent(paramElement, localElement);
/* 53:   */     }
/* 54:56 */     Element tmp101_100 = localElement;
/* 55:56 */     if (tmp101_100 == null) {
/* 56:56 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/jetbrains/jps/model/serialization/JDomSerializationUtil", "findOrCreateComponentElement" }));
/* 57:   */     }
/* 58:56 */     return tmp101_100;
/* 59:   */   }
/* 60:   */   
/* 61:   */   public static void addComponent(Element paramElement1, Element paramElement2)
/* 62:   */   {
/* 63:60 */     String str1 = paramElement2.getAttributeValue("name");
/* 64:61 */     Element localElement1 = findComponent(paramElement1, str1);
/* 65:62 */     if (localElement1 != null) {
/* 66:63 */       paramElement1.removeContent(localElement1);
/* 67:   */     }
/* 68:66 */     for (int i = 0; i < paramElement1.getContent().size(); i++)
/* 69:   */     {
/* 70:67 */       Object localObject = paramElement1.getContent().get(i);
/* 71:68 */       if ((localObject instanceof Element))
/* 72:   */       {
/* 73:69 */         Element localElement2 = (Element)localObject;
/* 74:70 */         if (localElement2.getName().equals("component"))
/* 75:   */         {
/* 76:71 */           String str2 = localElement2.getAttributeValue("name");
/* 77:72 */           if (str1.compareTo(str2) < 0)
/* 78:   */           {
/* 79:73 */             paramElement1.addContent(i, paramElement2);
/* 80:74 */             return;
/* 81:   */           }
/* 82:   */         }
/* 83:   */       }
/* 84:   */     }
/* 85:79 */     paramElement1.addContent(paramElement2);
/* 86:   */   }
/* 87:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.serialization.JDomSerializationUtil

 * JD-Core Version:    0.7.0.1

 */